package cn.edu.nwpu.warehousemanagement.pojo;

import cn.edu.nwpu.warehousemanagement.constantEnum.UserRole;
import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.stereotype.Component;

@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@DynamicUpdate
@Table(
        name = "user_info",
        uniqueConstraints = @UniqueConstraint(
                columnNames = "username",  // 唯一字段名
                name = "uc_user_username"  // 自定义约束名
        )
)
@Component
public class User extends BaseEntity {

    @Column(name = "username", length = 50, nullable = false, unique = true)
    private String username;

    @Column(name = "password", length = 100, nullable = false)
    private String password;

    // 真实姓名：非空，长度50
    @Column(name = "real_name", length = 50, nullable = false)
    private String realName;

    // 邮箱：可选，长度100
    @Column(name = "email", length = 100)
    @Email
    private String email;

    // 电话：可选，长度20
    @Column(name = "phone", length = 20)
    private String phone;

//    private String nickname;
//    private String address;
//    private String avatar;

    // 角色：非空，枚举类型
    @Enumerated(EnumType.STRING)
    @Column(name = "role", length = 20, nullable = false, columnDefinition = "VARCHAR(20)")
    private UserRole role;


}

